﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using MySql.Data.MySqlClient;
using System.Windows.Forms;

namespace CodeRobot.DAL
{
    /// <summary>
    /// 通用模块
    /// </summary>
    public class CommonHelper
    {
        /// <summary>
        /// 获取表中的主键ID
        /// </summary>
        /// <param name="strTableName">表名</param>
        /// <returns></returns>
        public static string GetPrimaryKey(string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    strColumnComment = GetColumnKeyComment(strColumnComment);

                    if (strColumnKey == "PRI")
                    {
                        strReturnValue = strColumnName;
                        break;
                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取表中的主键ID", "GetPrimaryKey",false);
            }

            return strReturnValue;

        }


        /// <summary>
        /// 检测是否存在日期字段
        /// </summary>
        /// <param name="strTableName">表名</param>
        /// <returns></returns>
        public static bool GetCreateAtKey(string strTableName)
        {
            bool bValue = false;

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    strColumnComment = GetColumnKeyComment(strColumnComment);

                    if (strColumnName == "created_at")
                    {
                        bValue = true;
                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "检测是否存在日期字段", "GetCreateAtKey", false);
            }

            return bValue;

        }

        /// <summary>
        /// 获取表中的主键ID
        /// </summary>
        /// <param name="strTableName">表名</param>
        /// <returns></returns>
        public static string GetPrimaryKeyDataType(string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strDataType = dr["DATA_TYPE"].ToString();//数据类型
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    strColumnComment = GetColumnKeyComment(strColumnComment);

                    if (strColumnKey == "PRI")
                    {
                        strReturnValue = strDataType;
                        break;
                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取表中的主键ID", "GetPrimaryKey", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取表注释，如：新闻表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetTableComment(string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    strColumnComment = GetColumnKeyComment(strColumnComment);

                    if (!string.IsNullOrEmpty(strColumnComment))
                    {
                        strColumnComment = strColumnComment.Replace("表ID","");
                    }

                    if (strColumnKey == "PRI")
                    {
                        strReturnValue = strColumnComment;
                        break;
                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取表注释", "GetTableComment",false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 处理表中的列名注释
        /// </summary>
        /// <param name="strColumnComment">原列名注释</param>
        /// <returns></returns>
        public static string GetColumnKeyComment(string strColumnComment)
        {
            string strReturnString = "";

            try
            {
                strColumnComment = strColumnComment.Replace("{下拉}", "");
                strColumnComment = strColumnComment.Replace("{勾选}", "");
                strColumnComment = strColumnComment.Replace("{单选}", "");
                strColumnComment = strColumnComment.Replace("{复选}", "");
                strColumnComment = strColumnComment.Replace("{图片}", "");
                strColumnComment = strColumnComment.Replace("{开关}", "");
                strColumnComment = strColumnComment.Replace("{搜索}", "");
                strColumnComment = strColumnComment.Replace("{富文本}", "");
                strColumnComment = strColumnComment.Replace("{TEXTAREA}", "");
                strColumnComment = strColumnComment.Replace("{MutiPages}", "");
                strColumnComment = strColumnComment.Replace("{ParentPages}", "");
                strColumnComment = strColumnComment.Replace("ID", "");
                strColumnComment = strColumnComment.Replace("1=", "");
                strColumnComment = strColumnComment.Replace("0=", "");

                if (strColumnComment.Contains("]"))
                {
                    string[] splitStr = strColumnComment.Split(new char[] { ']' });
                    strReturnString = splitStr[1];
                }
                else if (strColumnComment.Contains(":"))
                {
                    string[] splitStr = strColumnComment.Split(new char[] { ':' });
                    strReturnString = splitStr[0];
                }
                else
                {
                    strReturnString = strColumnComment;
                }

            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CommonHelper), ex, "处理表中的列名注释", "GetColumnKeyComment",false);
            }

            return strReturnString;
        }

        public static string GetColumnKeyCommentRight(string strColumnComment)
        {
            string strReturnString = "";

            try
            {
                strColumnComment = strColumnComment.Replace("{下拉}", "");
                strColumnComment = strColumnComment.Replace("{勾选}", "");
                strColumnComment = strColumnComment.Replace("{单选}", "");
                strColumnComment = strColumnComment.Replace("{复选}", "");
                strColumnComment = strColumnComment.Replace("{图片}", "");
                strColumnComment = strColumnComment.Replace("{搜索}", "");
                strColumnComment = strColumnComment.Replace("{开关}", "");
                strColumnComment = strColumnComment.Replace("{富文本}", "");
                strColumnComment = strColumnComment.Replace("1=", "");
                strColumnComment = strColumnComment.Replace("0=", "");
                strColumnComment = strColumnComment.Replace("{TEXTAREA}", "");
                strColumnComment = strColumnComment.Replace("{MutiPages}", "");
                strColumnComment = strColumnComment.Replace("{ParentPages}", "");

                if (strColumnComment.Contains("]"))
                {
                    string[] splitStr = strColumnComment.Split(new char[] { ']' });
                    strReturnString = splitStr[1];
                }
                else if (strColumnComment.Contains(":"))
                {
                    string[] splitStr = strColumnComment.Split(new char[] { ':' });
                    strReturnString = splitStr[1];
                }
                else
                {
                    strReturnString = strColumnComment;
                }

            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CommonHelper), ex, "处理表中的列名注释", "GetColumnKeyComment", false);
            }

            return strReturnString;
        }


        /// <summary>
        /// 生成首字母大写表名
        /// </summary>
        /// <param name="strTableName">表名</param>
        /// <returns></returns>
        public static string GetTableNameUpper(string strTableName)
        {
            string strReturnValue = "";

            try
            {
                if (strTableName.Contains("_"))
                {
                    string[] splitTableName = strTableName.Split(new char[] { '_' });
                    string strWordOne = splitTableName[0].ToString();
                    string strWordTwo = splitTableName[1].ToString();

                    string strNewWordOne = strWordOne.Substring(0, 1);
                    strWordOne = strNewWordOne.ToUpper() + strWordOne.Substring(1);

                    string strNewstrWordTwo = strWordTwo.Substring(0, 1);
                    strWordTwo = strNewstrWordTwo.ToUpper() + strWordTwo.Substring(1);

                    strReturnValue = strWordOne + strWordTwo;

                }
                else
                {
                    string strWords = strTableName.Substring(0, 1);
                    strWords = strWords.ToUpper() + strTableName.Substring(1);
                    strReturnValue = strWords;
                }
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CommonHelper), ex, "生成首字母大写表名", "GetTableNameUpper",false);
            }

            return strReturnValue;
        }

        /// <summary>
        /// 根据生成首字母大写的表名，再次把首字母强制为小写,-后为大写
        /// </summary>
        /// <param name="strTableNameUpper"></param>
        /// <returns></returns>
        public static string GetTableNameFirstLowerSecondUpper(string strTableNameUpper)
        {
            string strReturnValue = "";

            try
            {
                string strNewWordOne = strTableNameUpper.Substring(0, 1);
                strTableNameUpper = strNewWordOne.ToLower() + strTableNameUpper.Substring(1, strTableNameUpper.Length - 1);

                strReturnValue = strTableNameUpper;
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CommonHelper), ex, "根据生成首字母大写的表名，再次把首字母强制为小写", "GetTableNameFirstLower", false);
            }

            return strReturnValue;
        }

        /// <summary>
        /// 生成首字母大写
        /// </summary>
        /// <param name="strTableNameUpper"></param>
        /// <returns></returns>
        public static string GetTableNameFirstUpper(string strTableNameUpper)
        {
            string strReturnValue = "";

            try
            {
                string strNewWordOne = strTableNameUpper.Substring(0, 1);
                strTableNameUpper = strNewWordOne.ToUpper() + strTableNameUpper.Substring(1, strTableNameUpper.Length - 1);

                strReturnValue = strTableNameUpper;
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CommonHelper), ex, "根据生成首字母大写的表名，再次把首字母强制为小写", "GetTableNameFirstLower", false);
            }

            return strReturnValue;
        }

        /// <summary>
        /// 获取类名，过滤“_”前面的字符
        /// </summary>
        /// <param name="strTableName">表名</param>
        /// <returns></returns>
        public static string GetClassName(string strTableName)
        {
            string strReturnValue = "";

            try
            {
                if (strTableName.Contains("_"))
                {
                    //djy_communist_org_in
                    string[] splitNames = strTableName.Split(new char[] { '_' });
                    if (splitNames.Length == 2)
                    {
                        strReturnValue = splitNames[1];
                    }
                    if (splitNames.Length == 3)
                    {
                        string strItem2 = GetTableNameUpper(splitNames[2]);
                        strReturnValue = splitNames[1] + strItem2;
                    }
                    if (splitNames.Length == 4)
                    {
                        string strItem2 = GetTableNameUpper(splitNames[2]);
                        string strItem3 = GetTableNameUpper(splitNames[3]);
                        strReturnValue = splitNames[1] + strItem2 + strItem3;
                    }
                    if (splitNames.Length == 5)
                    {
                        string strItem2 = GetTableNameUpper(splitNames[2]);
                        string strItem3 = GetTableNameUpper(splitNames[3]);
                        string strItem4 = GetTableNameUpper(splitNames[4]);
                        strReturnValue = splitNames[1] + strItem2 + strItem3 + strItem4;
                    }
                    if (splitNames.Length == 6)
                    {
                        string strItem2 = GetTableNameUpper(splitNames[2]);
                        string strItem3 = GetTableNameUpper(splitNames[3]);
                        string strItem4 = GetTableNameUpper(splitNames[4]);
                        string strItem5 = GetTableNameUpper(splitNames[5]);
                        strReturnValue = splitNames[1] + strItem2 + strItem3 + strItem4 + strItem5;
                    }

                }
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CommonHelper), ex, "获取类名", "GetClassName",false);
            }

            return strReturnValue;
        }

        /// <summary>
        /// 获取首字母小写表名
        /// </summary>
        /// <param name="strTableName">表名</param>
        /// <returns></returns>
        public static string GetTableNameFirtWordLower(string strTableName)
        {
            string strReturnValue = "";     

            try
            {
                if (strTableName.Contains("_"))
                {
                    string[] splitNames = strTableName.Split(new char[] { '_' });
                    string strBehind = splitNames[1].ToString();

                    string strNewWordOne = strBehind.Substring(0, 1);
                    strNewWordOne = strNewWordOne.ToLower();
                    strReturnValue = strNewWordOne + strBehind.Substring(1, strBehind.Length - 1);
                }
                else
                {
                    string strNewWordOne = strTableName.Substring(0, 1);
                    strNewWordOne = strNewWordOne.ToLower();
                    strReturnValue = strNewWordOne + strTableName.Substring(1, strTableName.Length - 1);
                }
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CommonHelper), ex, "获取首字母小写表名", "GetTableNameFirtWordLower",false);
            }

            return strReturnValue;
        }


        /// <summary>
        /// 获取表中所有字段，不包含主键
        /// </summary>
        /// <param name="strTableName">表名</param>
        /// <returns></returns>
        public static string GetAllColumnNameNotKey(string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,COLUMN_KEY,COLUMN_COMMENT FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString().Trim();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();

                    if (strColumnKey != "PRI")
                    {
                        strReturnValue += strColumnName + ",";

                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取表中所有字段", "GetAllColumnName", false);
            }

            if (!string.IsNullOrEmpty(strReturnValue))
            {
                strReturnValue = strReturnValue.Substring(0, strReturnValue.Length - 1);
            }

            return strReturnValue;
        }

        public static string GetSpecialColumnNameNotKey(string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,COLUMN_KEY,COLUMN_COMMENT FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString().Trim();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();

                    if (strColumnKey != "PRI")
                    {
                        if (!strColumnComment.Contains("{添加排除}"))
                        {
                            strReturnValue += strColumnName + ",";
                        }

                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取表中所有字段", "GetAllColumnName", false);
            }

            if (!string.IsNullOrEmpty(strReturnValue))
            {
                strReturnValue = strReturnValue.Substring(0, strReturnValue.Length - 1);
            }

            return strReturnValue;
        }

        /// <summary>
        /// 获取表中所有字段
        /// </summary>
        /// <param name="strTableName">表名</param>
        /// <returns></returns>
        public static string GetAllColumnName(string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,COLUMN_KEY,COLUMN_COMMENT FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString().Trim();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();

                    strReturnValue += strColumnName + ",";
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取表中所有字段", "GetAllColumnName", false);
            }

            if (!string.IsNullOrEmpty(strReturnValue))
            {
                strReturnValue = strReturnValue.Substring(0, strReturnValue.Length - 1);
            }

            return strReturnValue;
        }

        /// <summary>
        /// 获取表中部分字段，过滤掉排除的
        /// </summary>
        /// <param name="strTableName">表名</param>
        /// <returns></returns>
        public static string GetSpecialColumnName(string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,COLUMN_KEY,COLUMN_COMMENT FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString().Trim();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();

                    if (!strColumnComment.Contains("{添加排除}"))
                    {
                        strReturnValue += strColumnName + ",";
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取表中所有字段", "GetAllColumnName", false);
            }

            if (!string.IsNullOrEmpty(strReturnValue))
            {
                strReturnValue = strReturnValue.Substring(0, strReturnValue.Length - 1);
            }

            return strReturnValue;
        }

        /// <summary>
        /// 获取表中所有字段@
        /// </summary>
        /// <param name="strTableName">表名</param>
        /// <returns></returns>
        public static string GetAllColumnNameForAt(string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,COLUMN_KEY,COLUMN_COMMENT FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString().Trim();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();

                    if (strColumnKey != "PRI")
                    {
                        strReturnValue += "@" + strColumnName + ",";
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取表中所有字段@", "GetAllColumnNameForAt", false);
            }

            if (!string.IsNullOrEmpty(strReturnValue))
            {
                strReturnValue = strReturnValue.Substring(0, strReturnValue.Length - 1);
            }

            return strReturnValue;
        }

        public static string GetSpecialColumnNameForAt(string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,COLUMN_KEY,COLUMN_COMMENT FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString().Trim();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();

                    if (strColumnKey != "PRI")
                    {
                        if (!strColumnComment.Contains("{添加排除}"))
                        {
                            strReturnValue += "@" + strColumnName + ",";
                        }

                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取表中所有字段@", "GetAllColumnNameForAt", false);
            }

            if (!string.IsNullOrEmpty(strReturnValue))
            {
                strReturnValue = strReturnValue.Substring(0, strReturnValue.Length - 1);
            }

            return strReturnValue;
        }

        /// <summary>
        /// 获取表中字段数量
        /// </summary>
        /// <param name="strTableName">表名</param>
        /// <returns></returns>
        public static int GetColumnNum(string strTableName)
        {
            int nNum = 0;

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    nNum++;
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取表中字段数量", "GetColumnNum", false);
            }

            //减去自增主键
            nNum = nNum - 1;

            return nNum;
        }


        /// <summary>
        /// 获取表中的Name字段
        /// </summary>
        /// <param name="strTableName">表名</param>
        /// <returns></returns>
        public static string GetKeyNameForSelect(string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    strColumnComment = GetColumnKeyComment(strColumnComment);

                    if (strColumnName.Contains("_name"))
                    {
                        strReturnValue = strColumnName;
                        break;
                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取表中的Name字段", "GetKeyNameForSelect", false);
            }

            return strReturnValue;

        }


        /// <summary>
        /// 检测字段是否存在
        /// </summary>
        /// <param name="strTableName"></param>
        /// <param name="strCheckColumnName"></param>
        /// <returns></returns>
        public static bool ChecktCreatedAtKey(string strTableName, string strCheckColumnName)
        {
            bool bValue = false;

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    if (strColumnName == strCheckColumnName)
                    {
                        bValue = true;
                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "检测字段是否存在", "ChecktCreatedAtKey", false);
            }

            return bValue;

        }

        /// <summary>
        /// 获取存储内容的字段包含图片等
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetContentKey(string strTableName)
        {
            string result = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    if (strColumnName.Contains("_intro") || strColumnName.Contains("_content"))
                    {
                        result = strColumnName;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取存储内容的字段包含图片等", "GetContentKey", false);
            }

            return result;

        }

        /// <summary>
        /// 获取可用来检测是否重复添加的字段名
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetCheckValue(string strTableName)
        {
            string result = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    if (strColumnName.Contains("_name") || strColumnName.Contains("_title"))
                    {
                        result = strColumnName;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取可用来检测是否重复添加的字段名", "GetCheckValue", false);
            }

            return result;

        }

        /// <summary>
        /// 检测是否bigint
        /// </summary>
        /// <param name="strTableName"></param>
        /// <param name="strPrimaryKey"></param>
        /// <returns></returns>
        public static bool ChecktKeyIsBigint(string strTableName, string strPrimaryKey)
        {
            bool bValue = false;

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    if (strColumnName == strPrimaryKey)
                    {
                        if (strColumnType.Contains("bigint"))
                        {
                            bValue = true;
                        }

                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "检测字段是否存在", "ChecktCreatedAtKey", false);
            }

            return bValue;

        }

        /// <summary>
        /// 获取生成日志字段
        /// </summary>
        /// <param name="strTableName"></param>
        /// <param name="newTable"></param>
        /// <returns></returns>
        public static string GetSaveLogColumnName(string strTableName,string newTable)
        {
            string returnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    returnValue += "\","+ strColumnName + "=\" +"+ newTable + "." + strColumnName + "+";
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "检测字段是否存在", "GetSaveLogColumnName", false);
            }

            if (returnValue.Length>0)
            {
                returnValue = returnValue.Substring(0, returnValue.Length - 1);
            }

            return returnValue;

        }


        /// <summary>
        /// 获取详情页面左联Linq-list
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetDetailsSelectJoinList(string strDBName,string strTableName)
        {
            string returnValue = "";

            try
            {
                int num = 1;
                string strLeftJoin = "";
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    if (strColumnComment.Contains("{下拉}"))
                    {
                        //获取注释中的表名
                        string strColumnComment2 = strColumnComment.Replace("[", ",");
                        strColumnComment2 = strColumnComment2.Replace("]", ",");
                        string[] arrayComment = strColumnComment2.Split(new char[] { ',' });
                        //{搜索}{下拉},wlf_news_types,分类ID
                        string strGetNewTable = arrayComment[1];
                        strGetNewTable = CommonHelper.GetClassName(strGetNewTable);//类名
                        strGetNewTable = CommonHelper.GetTableNameUpper(strGetNewTable);

                        string strJoin = "";
                        if (num == 1)
                        {
                            strJoin = "from a in _context.Set<" + strGetNewTable + ">().Where(a => a." + strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        if (num == 2)
                        {
                            strJoin = "                             from b in _context.Set<" + strGetNewTable + ">().Where(b => b." + strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        if (num == 3)
                        {
                            strJoin = "                             from c in _context.Set<" + strGetNewTable + ">().Where(c => c." + strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        if (num == 4)
                        {
                            strJoin = "                             from d in _context.Set<" + strGetNewTable + ">().Where(d => d." + strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        if (num == 5)
                        {
                            strJoin = "                             from e in _context.Set<" + strGetNewTable + ">().Where(e => e." + strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        if (num == 6)
                        {
                            strJoin = "                             from f in _context.Set<" + strGetNewTable + ">().Where(f => f." + strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        if (num == 7)
                        {
                            strJoin = "                             from g in _context.Set<" + strGetNewTable + ">().Where(g => g." + strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        num++;

                        strLeftJoin += strJoin;
                    }

                    returnValue = strLeftJoin;
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取详情页面左联Linq", "GetDetailsSelectJoin", false);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取详情页面左联Linq-list Java
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetDetailsSelectJoinListForJava(string strTableName)
        {
            string returnValue = "";

            try
            {
                int num = 1;
                string strLeftJoin = "";
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    if (strColumnComment.Contains("{下拉}"))
                    {
                        //获取注释中的表名
                        string strColumnComment2 = strColumnComment.Replace("[", ",");
                        strColumnComment2 = strColumnComment2.Replace("]", ",");
                        string[] arrayComment = strColumnComment2.Split(new char[] { ',' });
                        //{搜索}{下拉},wlf_news_types,分类ID
                        string strGetNewTable = arrayComment[1];
                        //strGetNewTable = CommonHelper.GetClassName(strGetNewTable);//类名
                        //strGetNewTable = CommonHelper.GetTableNameUpper(strGetNewTable);

                        string strJoin = "";
                        if (num == 1)
                        {
                            strJoin = "		LEFT JOIN " + strGetNewTable + " a ON (item." + strColumnName + " = a." + strColumnName + ")\r\n";
                        }
                        if (num == 2)
                        {
                            strJoin = "		LEFT JOIN " + strGetNewTable + " b ON (item." + strColumnName + " = b." + strColumnName + ")\r\n";
                        }
                        if (num == 3)
                        {
                            strJoin = "		LEFT JOIN " + strGetNewTable + " c ON (item." + strColumnName + " = c." + strColumnName + ")\r\n";
                        }
                        if (num == 4)
                        {
                            strJoin = "		LEFT JOIN " + strGetNewTable + " d ON (item." + strColumnName + " = d." + strColumnName + ")\r\n";
                        }
                        if (num == 5)
                        {
                            strJoin = "		LEFT JOIN " + strGetNewTable + " e ON (item." + strColumnName + " = e." + strColumnName + ")\r\n";
                        }
                        if (num == 6)
                        {
                            strJoin = "		LEFT JOIN " + strGetNewTable + " f ON (item." + strColumnName + " = f." + strColumnName + ")\r\n";
                        }
                        if (num == 7)
                        {
                            strJoin = "		LEFT JOIN " + strGetNewTable + " g ON (item." + strColumnName + " = g." + strColumnName + ")\r\n";
                        }
                        num++;

                        strLeftJoin += strJoin;
                    }

                    returnValue = strLeftJoin;
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取详情页面左联Linq", "GetDetailsSelectJoin", false);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取搜索字段列表 Java
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSearchListForJava(string strTableName)
        {
            string returnValue = "";

            try
            {
                string strLeftJoin = "";
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    string strClassName = CommonHelper.GetClassName(strTableName);//类名
                    strClassName = CommonHelper.GetTableNameUpper(strClassName);
                    string strTableNameSpec = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName);//如：newsTypes
                    string strTableNameLower = strTableNameSpec.ToLower();//如：newstypes

                    if (strColumnComment.Contains("{搜索}"))
                    {
                        //获取注释中的表名
                        string strValue= "		<if test=\""+ strTableNameLower + "." + strColumnName + " != null and " + strTableNameLower + "." + strColumnName + " != ''\">\r\n";
                        strValue += "            AND a." + strColumnName + " LIKE #{" + strTableNameLower + "." + strColumnName + "}\r\n";
                        strValue += "        </if>\r\n";

                        strLeftJoin += strValue;
                    }

                    returnValue = strLeftJoin;
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取详情页面左联Linq", "GetDetailsSelectJoin", false);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取详情页面左联Linq
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetDetailsSelectJoin(string strDBName, string strTableName)
        {
            string returnValue = "";

            try
            {
                int num = 1;
                string strLeftJoin = "";
                string strLeftColumn = "";
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    if (strColumnComment.Contains("{下拉}"))
                    {
                        //获取注释中的表名
                        string strColumnComment2 = strColumnComment.Replace("[",",");
                        strColumnComment2 = strColumnComment2.Replace("]", ",");
                        string[] arrayComment = strColumnComment2.Split(new char[] { ','});
                        //{搜索}{下拉},wlf_news_types,分类ID
                        string strGetNewTable = arrayComment[1];
                        string strJoin = "";
                        if (num==1)
                        {
                            strJoin = "from a in _context." + strGetNewTable + ".Where(a => a."+ strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        if (num == 2)
                        {
                            strJoin = "                                  from b in _context." + strGetNewTable + ".Where(b => b." + strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        if (num == 3)
                        {
                            strJoin = "                                  from c in _context." + strGetNewTable + ".Where(c => c." + strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        if (num == 4)
                        {
                            strJoin = "                                  from d in _context." + strGetNewTable + ".Where(d => d." + strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        if (num == 5)
                        {
                            strJoin = "                                  from e in _context." + strGetNewTable + ".Where(e => e." + strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        if (num == 6)
                        {
                            strJoin = "                                  from f in _context." + strGetNewTable + ".Where(f => f." + strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        if (num == 7)
                        {
                            strJoin = "                                  from g in _context." + strGetNewTable + ".Where(g => g." + strColumnName + " == item." + strColumnName + ").DefaultIfEmpty()\r\n";
                        }
                        num++;

                        strLeftJoin += strJoin;
                    }

                    returnValue = strLeftJoin;
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取详情页面左联Linq", "GetDetailsSelectJoin", false);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取字段结果 Java
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetColumnListResultForJava(string strTableName)
        {
            string returnValue = "";

            try
            {
                string strLeftJoin = "";
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    string strClassName = CommonHelper.GetClassName(strTableName);//类名
                    strClassName = CommonHelper.GetTableNameUpper(strClassName);
                    string strTableNameSpec = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName);//如：newsTypes
                    string strTableNameLower = strTableNameSpec.ToLower();//如：newstypes

                    string strJavaColumnName = CommonHelper.GetTableNameUpper(strColumnName);
                    strJavaColumnName = CommonHelper.GetTableNameUpper(strJavaColumnName);//News
                    strJavaColumnName = CommonHelper.GetTableNameFirstLowerSecondUpper(strJavaColumnName);

                    string strValue = "        <result column=\"" + strColumnName + "\" property=\"" + strJavaColumnName + "\" />\r\n";
                    strLeftJoin += strValue;

                    returnValue = strLeftJoin;
                }
                dr.Dispose();
                cn.Close();

                if (returnValue.Length>0)
                {
                    returnValue = returnValue.Substring(0, returnValue.Length - 2);
                }
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取详情页面左联Linq", "GetDetailsSelectJoin", false);
            }

            return returnValue;

        }


        /// <summary>
        /// 获取字段 Java
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetColumnListForJava(string strTableName)
        {
            string returnValue = "";

            try
            {
                string strLeftJoin = "";
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    string strClassName = CommonHelper.GetClassName(strTableName);//类名
                    strClassName = CommonHelper.GetTableNameUpper(strClassName);
                    string strTableNameSpec = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName);//如：newsTypes
                    string strTableNameLower = strTableNameSpec.ToLower();//如：newstypes

                    string strJavaColumnName = CommonHelper.GetTableNameUpper(strColumnName);
                    strJavaColumnName = CommonHelper.GetTableNameUpper(strJavaColumnName);//News
                    strJavaColumnName = CommonHelper.GetTableNameFirstLowerSecondUpper(strJavaColumnName);

                    string strValue = strColumnName+" AS "+ strJavaColumnName + ",";
                    strLeftJoin += strValue;

                    returnValue = strLeftJoin;
                }
                dr.Dispose();
                cn.Close();

                if (returnValue.Length>0)
                {
                    returnValue = returnValue.Substring(0, returnValue.Length - 1);
                }
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取详情页面左联Linq", "GetDetailsSelectJoin", false);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取精准搜索字段 Java
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSearchEqualListForJava(string strTableName)
        {
            string returnValue = "";

            try
            {
                string columnList = "";
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    string strClassName = CommonHelper.GetClassName(strTableName);//类名
                    strClassName = CommonHelper.GetTableNameUpper(strClassName);
                    string strTableNameSpec = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName);//如：newsTypes
                    string strTableNameLower = strTableNameSpec.ToLower();//如：newstypes

                    string strJavaColumnName = CommonHelper.GetTableNameUpper(strColumnName);
                    strJavaColumnName = CommonHelper.GetTableNameUpper(strJavaColumnName);//News
                    strJavaColumnName = CommonHelper.GetTableNameFirstLowerSecondUpper(strJavaColumnName);

                    string strValue = "        <if test=\""+ strJavaColumnName + " != null \">\r\n";
                    strValue += "            AND " + strColumnName + " = #{" + strJavaColumnName + "}  <!-- " + strColumnComment + " -->\r\n";
                    strValue += "        </if>\r\n";

                    columnList += strValue;

                    returnValue = columnList;
                }
                dr.Dispose();
                cn.Close();

                if (returnValue.Length > 0)
                {
                    returnValue = returnValue.Substring(0, returnValue.Length - 2);
                }
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取详情页面左联Linq", "GetDetailsSelectJoin", false);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取模糊搜索字段 Java
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSearchLikeListForJava(string strTableName)
        {
            string returnValue = "";

            try
            {
                string columnList = "";
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    string strClassName = CommonHelper.GetClassName(strTableName);//类名
                    strClassName = CommonHelper.GetTableNameUpper(strClassName);
                    string strTableNameSpec = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName);//如：newsTypes
                    string strTableNameLower = strTableNameSpec.ToLower();//如：newstypes

                    string strJavaColumnName = CommonHelper.GetTableNameUpper(strColumnName);
                    strJavaColumnName = CommonHelper.GetTableNameUpper(strJavaColumnName);//News
                    strJavaColumnName = CommonHelper.GetTableNameFirstLowerSecondUpper(strJavaColumnName);

                    string strValue = "        <if test=\"" + strJavaColumnName + " != null and " + strJavaColumnName + " != ''\">\r\n";
                    strValue += "            AND "+ strColumnName + " LIKE '%${" + strJavaColumnName + "}%'  <!-- " + strColumnComment + " -->\r\n";
                    strValue += "        </if>\r\n";

                    columnList += strValue;

                    returnValue = columnList;
                }
                dr.Dispose();
                cn.Close();

                if (returnValue.Length > 0)
                {
                    returnValue = returnValue.Substring(0, returnValue.Length - 2);
                }
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取详情页面左联Linq", "GetDetailsSelectJoin", false);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取详情页面左联字段列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetDetailsSelectJoinColumn(string strDBName,string strTableName,string strPrimaryKey,string strMainColumnList)
        {
            string returnValue = "";

            try
            {
                int num = 1;
                string strLeftColumn = "";
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                CodeRobot.Utility.LogHelper.Debug(typeof(CommonHelper), "sql=" + strSql, "GetDetailsSelectJoinColumn", false);
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    if (strColumnComment.Contains("{下拉}"))
                    {
                        //获取注释中的表名
                        string strColumnComment2 = strColumnComment.Replace("[", ",");
                        strColumnComment2 = strColumnComment2.Replace("]", ",");
                        string[] arrayComment = strColumnComment2.Split(new char[] { ',' });
                        //{搜索}{下拉},wlf_news_types,分类ID
                        string strGetNewTable = arrayComment[1];
                        string strColumnList = "";

                        if (num == 1)
                        {
                            strColumnList = GetLeftSelectColumnName(strGetNewTable, "a", strMainColumnList, strDBName);
                        }
                        if (num == 2)
                        {

                            strColumnList = GetLeftSelectColumnName(strGetNewTable, "b", strMainColumnList, strDBName);
                        }
                        if (num == 3)
                        {

                            strColumnList = GetLeftSelectColumnName(strGetNewTable, "c", strMainColumnList, strDBName);
                        }
                        if (num == 4)
                        {

                            strColumnList = GetLeftSelectColumnName(strGetNewTable, "d", strMainColumnList, strDBName);
                        }
                        if (num == 5)
                        {

                            strColumnList = GetLeftSelectColumnName(strGetNewTable, "e", strMainColumnList, strDBName);
                        }
                        if (num == 6)
                        {

                            strColumnList = GetLeftSelectColumnName(strGetNewTable, "f", strMainColumnList, strDBName);
                        }
                        if (num == 7)
                        {

                            strColumnList = GetLeftSelectColumnName(strGetNewTable, "g", strMainColumnList, strDBName);
                        }
                        num++;

                        strLeftColumn += strColumnList;

                    }

                    returnValue =  strLeftColumn;
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取详情页面左联Linq", "GetDetailsSelectJoin", false);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取详情页面左联字段列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetDetailsSelectJoinColumn2(string strDBName, string strTableName, string strPrimaryKey, string strMainColumnList)
        {
            string returnValue = "";

            try
            {
                int num = 1;
                string strLeftColumn = "";
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                CodeRobot.Utility.LogHelper.Debug(typeof(CommonHelper), "sql=" + strSql, "GetDetailsSelectJoinColumn", false);
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    if (strColumnComment.Contains("{下拉}"))
                    {
                        //获取注释中的表名
                        string strColumnComment2 = strColumnComment.Replace("[", ",");
                        strColumnComment2 = strColumnComment2.Replace("]", ",");
                        string[] arrayComment = strColumnComment2.Split(new char[] { ',' });
                        //{搜索}{下拉},wlf_news_types,分类ID
                        string strGetNewTable = arrayComment[1];
                        string strColumnList = "";

                        if (num == 1)
                        {
                            strColumnList = GetLeftSelectColumnNameNew(strGetNewTable, "a", strMainColumnList, strDBName);
                        }
                        if (num == 2)
                        {

                            strColumnList = GetLeftSelectColumnNameNew(strGetNewTable, "b", strMainColumnList, strDBName);
                        }
                        if (num == 3)
                        {

                            strColumnList = GetLeftSelectColumnNameNew(strGetNewTable, "c", strMainColumnList, strDBName);
                        }
                        if (num == 4)
                        {

                            strColumnList = GetLeftSelectColumnNameNew(strGetNewTable, "d", strMainColumnList, strDBName);
                        }
                        if (num == 5)
                        {

                            strColumnList = GetLeftSelectColumnNameNew(strGetNewTable, "e", strMainColumnList, strDBName);
                        }
                        if (num == 6)
                        {

                            strColumnList = GetLeftSelectColumnNameNew(strGetNewTable, "f", strMainColumnList, strDBName);
                        }
                        if (num == 7)
                        {

                            strColumnList = GetLeftSelectColumnNameNew(strGetNewTable, "g", strMainColumnList, strDBName);
                        }
                        num++;

                        strLeftColumn += strColumnList;

                    }

                    returnValue = strLeftColumn;
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取详情页面左联Linq", "GetDetailsSelectJoin", false);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取左联字段列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetLeftSelectColumnName(string strTableName,string shortChar,string strMainColumnList,string strDBName)
        {
            string returnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    if (!strMainColumnList.Contains(strColumnName))
                    {
                        if (strColumnName.Contains("name"))
                        {
                            returnValue += "                                 " + shortChar + "." + strColumnName + ",\r\n";
                        }
                        
                    }

                    
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取左联字段列表", "GetLeftSelectColumnName", false);
            }

            if (returnValue.Length > 0)
            {
                returnValue = returnValue.Substring(0, returnValue.Length - 1);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取左联字段列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetLeftSelectColumnName2(string strProjectName, string strDBName,string strTableName, string shortChar)
        {
            string returnValue = "";
            string strColumnNames = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "'  ORDER BY ordinal_position ";
                CodeRobot.Utility.LogHelper.Debug(typeof(CommonHelper), "sql=" + strSql, "GetLeftSelectColumnName2", false);
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    strColumnNames = strColumnName + ",";
                    returnValue += "                                 " + shortChar + "." + strColumnName + ",\r\n";
                    if (strColumnComment.Contains("{图片}") || strColumnComment.Contains("头像") || strColumnName.Contains("avatar"))
                    {
                        returnValue += "                                 show_" + strColumnName + " = CommonHelper.GetImg(item." + strColumnName + ", GetSettingInfoValue((int)ENUMHelper.SettingInfoType.AliyunCallbackServer)),\r\n";
                    }
                    if (strColumnComment.Contains("[") && strColumnName.Contains("_id"))
                    {
                        // 取表名
                        string strGetTableName = "";
                        try
                        {
                            string newComment = strColumnComment;
                            newComment = newComment.Replace("[", "#");
                            newComment = newComment.Replace("]", "#");
                            string[] splitComents = newComment.Split(new char[] { '#' });
                            strGetTableName = splitComents[1];
                        }
                        catch (Exception)
                        {
                        }
                        // 取字段名
                        string showColumnName = strColumnName;
                        showColumnName = strColumnName.Replace("_id", "_name");

                        returnValue += "                                 "+ showColumnName + " = item." + strColumnName + " > 0 ? _context."+ strGetTableName + ".FirstOrDefault(t => t." + strColumnName + " == item." + strColumnName + ")!."+ showColumnName + " : \"-\",\r\n";
                    }
                    //if (strColumnName == "user_id")
                    //{
                    //    // returnValue += "                                 item.user_id,\r\n";
                    //    returnValue += "                                 user_name = item.user_id > 0 ? _context.mpp_users.FirstOrDefault(t => t.user_id == item.user_id).user_name : \"-\",\r\n";
                    //}
                }
                dr.Dispose();
                cn.Close();

                if (strColumnNames.Contains("created_at"))
                {
                    returnValue += "                                 format_time = item.created_at.ToString(\"yyyy-MM-dd HH:mm\"),\r\n";
                }

                returnValue = returnValue.Substring(0, returnValue.Length - 2);
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取左联字段列表", "GetLeftSelectColumnName", false);
            }

            if (returnValue.Length > 0)
            {
                returnValue = returnValue.Substring(0, returnValue.Length - 1);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取左联字段列表-API
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetLeftSelectColumnNameAPI(string strProjectName, string strDBName, string strTableName, string shortChar)
        {
            string returnValue = "";
            string strColumnNames = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "'  ORDER BY ordinal_position ";
                CodeRobot.Utility.LogHelper.Debug(typeof(CommonHelper), "sql=" + strSql, "GetLeftSelectColumnName2", false);
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    strColumnNames = strColumnName + ",";
                    returnValue += "                                 " + shortChar + "." + strColumnName + ",\r\n";
                    if (strColumnComment.Contains("{图片}") || strColumnComment.Contains("头像") || strColumnName.Contains("avatar"))
                    {
                        returnValue += "                                 show_" + strColumnName + " = CommonHelper.GetCoverImg(item." + strColumnName + ", DataFilter.GetSettingInfoValue(_context, log, (int)ENUMHelper.SettingInfoType.AliyunCallbackServer)),\r\n";
                    }
                    if (strColumnComment.Contains("[") && strColumnName.Contains("_id"))
                    {
                        // 取表名
                        string strGetTableName = "";
                        try
                        {
                            string newComment = strColumnComment;
                            newComment = newComment.Replace("[", "#");
                            newComment = newComment.Replace("]", "#");
                            string[] splitComents = newComment.Split(new char[] { '#' });
                            strGetTableName = splitComents[1];
                        }
                        catch (Exception)
                        {
                        }
                        // 取字段名
                        string showColumnName = strColumnName;
                        showColumnName = strColumnName.Replace("_id", "_name");

                        returnValue += "                                 " + showColumnName + " = item." + strColumnName + " > 0 ? _context." + strGetTableName + ".FirstOrDefault(t => t." + strColumnName + " == item." + strColumnName + ")!." + showColumnName + " : \"-\",\r\n";
                    }
                    //if (strColumnName == "user_id")
                    //{
                    //    // returnValue += "                                 item.user_id,\r\n";
                    //    returnValue += "                                 user_name = item.user_id > 0 ? _context.mpp_users.FirstOrDefault(t => t.user_id == item.user_id).user_name : \"-\",\r\n";
                    //}
                }
                dr.Dispose();
                cn.Close();

                if (strColumnNames.Contains("created_at"))
                {
                    returnValue += "                                 format_time = item.created_at.ToString(\"yyyy-MM-dd HH:mm\"),\r\n";
                }

                returnValue = returnValue.Substring(0, returnValue.Length - 2);
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取左联字段列表", "GetLeftSelectColumnName", false);
            }

            if (returnValue.Length > 0)
            {
                returnValue = returnValue.Substring(0, returnValue.Length - 1);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取左联字段列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetLeftSelectColumnName3(string strProjectName, string strDBName, string strTableName, string shortChar)
        {
            string returnValue = "";
            string strColumnNames = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "'  ORDER BY ordinal_position ";
                CodeRobot.Utility.LogHelper.Debug(typeof(CommonHelper), "sql=" + strSql, "GetLeftSelectColumnName2", false);
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    strColumnNames = strColumnName + ",";
                    returnValue += "                    " + shortChar + "." + strColumnName + ",\r\n";
                    if (strColumnComment.Contains("{图片}"))
                    {
                        returnValue += "                    show_" + strColumnName + " = CommonHelper.GetCoverImg(item." + strColumnName + ", DataFilter.GetSettingInfoValue(_context, log, (int)ENUMHelper.SettingInfoType.AliyunCallbackServer)),\r\n";
                    }
                    if (strColumnComment.Contains("[") && strColumnName.Contains("_id"))
                    {
                        // 取表名
                        string strGetTableName = "";
                        try
                        {
                            string newComment = strColumnComment;
                            newComment = newComment.Replace("[", "#");
                            newComment = newComment.Replace("]", "#");
                            string[] splitComents = newComment.Split(new char[] { '#' });
                            strGetTableName = splitComents[1];
                        }
                        catch (Exception)
                        {
                        }
                        // 取字段名
                        string showColumnName = strColumnName;
                        showColumnName = strColumnName.Replace("_id", "_name");

                        returnValue += "                                 " + showColumnName + " = item." + strColumnName + " > 0 ? _context." + strGetTableName + ".FirstOrDefault(t => t." + strColumnName + " == item." + strColumnName + ")!." + showColumnName + " : \"-\",\r\n";
                    }
                }
                dr.Dispose();
                cn.Close();

                if (strColumnNames.Contains("created_at"))
                {
                    returnValue += "                    format_time = item.created_at.ToString(\"yyyy-MM-dd HH:mm\"),\r\n";
                }

                returnValue = returnValue.Substring(0, returnValue.Length - 2);
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取左联字段列表", "GetLeftSelectColumnName", false);
            }

            if (returnValue.Length > 0)
            {
                returnValue = returnValue.Substring(0, returnValue.Length - 1);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取左联字段列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSelectColumnNameForGetById(string strProjectName, string strDBName, string strTableName, string shortChar)
        {
            string returnValue = "";
            string strColumnNames = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "'  ORDER BY ordinal_position ";
                CodeRobot.Utility.LogHelper.Debug(typeof(CommonHelper), "sql=" + strSql, "GetLeftSelectColumnName2", false);
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    strColumnNames = strColumnName + ",";
                    returnValue += "                    " + shortChar + "." + strColumnName + ",\r\n";
                    if (strColumnComment.Contains("{图片}"))
                    {
                        returnValue += "                    show_" + strColumnName + " = CommonHelper.GetCoverImg(item." + strColumnName + ", DataFilter.GetSettingInfoValue(_context, log, (int)ENUMHelper.SettingInfoType.AliyunCallbackServer)),\r\n";
                    }
                    if (strColumnComment.Contains("[") && strColumnName.Contains("_id"))
                    {
                        // 取表名
                        string strGetTableName = "";
                        try
                        {
                            string newComment = strColumnComment;
                            newComment = newComment.Replace("[", "#");
                            newComment = newComment.Replace("]", "#");
                            string[] splitComents = newComment.Split(new char[] { '#' });
                            strGetTableName = splitComents[1];
                        }
                        catch (Exception)
                        {
                        }
                        // 取字段名
                        string showColumnName = strColumnName;
                        showColumnName = strColumnName.Replace("_id", "_name");

                        returnValue += "                    " + showColumnName + " = item." + strColumnName + " > 0 ? _context." + strGetTableName + ".FirstOrDefault(t => t." + strColumnName + " == item." + strColumnName + ")!." + showColumnName + " : \"-\",\r\n";
                    }
                }
                dr.Dispose();
                cn.Close();

                if (strColumnNames.Contains("created_at"))
                {
                    returnValue += "                    format_time = item.created_at.ToString(\"yyyy-MM-dd HH:mm\"),\r\n";
                }

                returnValue = returnValue.Substring(0, returnValue.Length - 2);
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取左联字段列表", "GetLeftSelectColumnName", false);
            }

            if (returnValue.Length > 0)
            {
                returnValue = returnValue.Substring(0, returnValue.Length - 1);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取左联字段列表-API
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSelectColumnNameForGetByIdAPI(string strProjectName, string strDBName, string strTableName, string shortChar)
        {
            string returnValue = "";
            string strColumnNames = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "'  ORDER BY ordinal_position ";
                CodeRobot.Utility.LogHelper.Debug(typeof(CommonHelper), "sql=" + strSql, "GetLeftSelectColumnName2", false);
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    strColumnNames = strColumnName + ",";
                    returnValue += "                    " + shortChar + "." + strColumnName + ",\r\n";
                    if (strColumnComment.Contains("{图片}"))
                    {
                        returnValue += "                    show_" + strColumnName + " = CommonHelper.GetCoverImg(item." + strColumnName + ", DataFilter.GetSettingInfoValue(_context, log, (int)ENUMHelper.SettingInfoType.AliyunCallbackServer)),\r\n";
                    }
                    if (strColumnComment.Contains("[") && strColumnName.Contains("_id"))
                    {
                        // 取表名
                        string strGetTableName = "";
                        try
                        {
                            string newComment = strColumnComment;
                            newComment = newComment.Replace("[", "#");
                            newComment = newComment.Replace("]", "#");
                            string[] splitComents = newComment.Split(new char[] { '#' });
                            strGetTableName = splitComents[1];
                        }
                        catch (Exception)
                        {
                        }
                        // 取字段名
                        string showColumnName = strColumnName;
                        showColumnName = strColumnName.Replace("_id", "_name");

                        returnValue += "                    " + showColumnName + " = item." + strColumnName + " > 0 ? _context." + strGetTableName + ".FirstOrDefault(t => t." + strColumnName + " == item." + strColumnName + ")!." + showColumnName + " : \"-\",\r\n";
                    }
                }
                dr.Dispose();
                cn.Close();

                if (strColumnNames.Contains("created_at"))
                {
                    returnValue += "                    format_time = item.created_at.ToString(\"yyyy-MM-dd HH:mm\"),\r\n";
                }

                returnValue = returnValue.Substring(0, returnValue.Length - 2);
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取左联字段列表", "GetLeftSelectColumnName", false);
            }

            if (returnValue.Length > 0)
            {
                returnValue = returnValue.Substring(0, returnValue.Length - 1);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取左联字段列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetLeftSelectColumnNameNew(string strTableName, string shortChar, string strMainColumnList, string strDBName)
        {
            string returnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    if (!strMainColumnList.Contains(strColumnName))
                    {
                        if (strColumnName.Contains("name"))
                        {
                            returnValue += "                                      " + shortChar + "." + strColumnName + ",\r\n";
                        }

                    }


                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取左联字段列表", "GetLeftSelectColumnName", false);
            }

            if (returnValue.Length > 0)
            {
                returnValue = returnValue.Substring(0, returnValue.Length - 1);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取更新字段
        /// </summary>
        /// <param name="strNewName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetUpdateItems(string strDBName, string strNewName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

                    if (strColumnKey != "PRI" && strColumnName != "created_at")
                    {
                        // 排除关键字
                        string strValue = "                    item." + strColumnName + " = " + strNewName + "." + strColumnName + ";\r\n";
                        strReturnValue += strValue;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取搜索字段列表", "GetSearchItemList", false);
            }

            strReturnValue = strReturnValue.Substring(0, strReturnValue.Length - 2);

            return strReturnValue;
        }

        /// <summary>
        /// 获取导出Excel字段表头
        /// </summary>
        /// <param name="strDBName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetExportExcelItem(string strDBName, string strTableName)
        {
            string returnValue = "";

            try
            {
                int num = 1;
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "'  ORDER BY ordinal_position ";
                CodeRobot.Utility.LogHelper.Debug(typeof(CommonHelper), "sql=" + strSql, "GetLeftSelectColumnName2", false);
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释
                    strColumnComment = CommonHelper.GetColumnKeyComment(strColumnComment);

                    if (strColumnKey == "PRI")
                    {
                        returnValue += "                    worksheet.Cells[2, " + num + "].Value = \"ID\";\r\n";
                    }
                    else
                    {
                        returnValue += "                    worksheet.Cells[2, " + num + "].Value = \"" + strColumnComment + "\";\r\n";
                    }
                    num++;
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取导出Excel字段表头", "GetExportExcelItem", false);
            }

            if (returnValue.Length > 0)
            {
                returnValue = returnValue.Substring(0, returnValue.Length - 1);
            }

            return returnValue;

        }

        /// <summary>
        /// 获取导出Excel字段表头对应字段值
        /// </summary>
        /// <param name="strDBName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetExportExcelItemValue(string strDBName, string strTableName)
        {
            string returnValue = "";

            try
            {
                int num = 1;
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "'  ORDER BY ordinal_position ";
                CodeRobot.Utility.LogHelper.Debug(typeof(CommonHelper), "sql=" + strSql, "GetLeftSelectColumnName2", false);
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    if (strColumnName.Contains("created_at"))
                    {
                        returnValue += "                        worksheet.Cells[$\"" + ConvertToTitle(num) + "{i + 3}\"].Value = list[i].format_time;\r\n";
                    }
                    else if (strColumnName.Contains("is_"))
                    {
                        returnValue += "                        worksheet.Cells[$\"" + ConvertToTitle(num) + "{i + 3}\"].Value = list[i]." + strColumnName + " ? \"是\" : \"否\";\r\n";
                    }
                    else
                    {
                        if (!strColumnKey.Contains("PRI") && strColumnName.Contains("_id"))
                        {
                            strColumnName = strColumnName.Replace("_id", "_name");
                        }
                        if (!strColumnKey.Contains("PRI") && strColumnName.Contains("_img") && strColumnName.Contains("_path"))
                        {
                            strColumnName = "show_" + strColumnName;
                        }
                        returnValue += "                        worksheet.Cells[$\"" + ConvertToTitle(num) + "{i + 3}\"].Value = list[i]." + strColumnName + ";\r\n";
                    }
                    num++;
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取导出Excel字段表头对应字段值", "GetExportExcelItemValue", false);
            }

            if (returnValue.Length > 0)
            {
                returnValue = returnValue.Substring(0, returnValue.Length - 1);
            }

            return returnValue;

        }

        /// <summary>
        /// 生成Excel表头字母
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static string ConvertToTitle(int n)
        {
            if (n <= 26) return ((char)(n + 'A' - 1)).ToString();
            if (n % 26 == 0)
            {
                return ConvertToTitle(n / 26 - 1) + 'Z';
            }
            else
            {
                return ConvertToTitle(n / 26) + ConvertToTitle(n % 26);
            }
        }

        /// <summary>
        /// 获取搜索字段列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSearchItemList(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME,CHARACTER_MAXIMUM_LENGTH FROM `information_schema`.`COLUMNS` WHERE  TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "'  ORDER BY ordinal_position";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strMaxLength = dr["CHARACTER_MAXIMUM_LENGTH"].ToString();//字段长度
                    string strDataType = dr["DATA_TYPE"].ToString();//数据类型

                    string strInputType = "text";
                    if (strDataType == "int" || strDataType == "bigint" || strDataType == "smalint" || strDataType == "decimal" || strDataType == "double")
                    {
                        strInputType = "number";
                    }

                    if (strColumnComment.Contains("{搜索}"))
                    {
                        if (strMaxLength.Length > 2000)
                        {
                            strMaxLength = "50";
                        }
                        string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                        if (strColumnComment.Contains("{下拉}"))
                        {
                            string strValue = "                <div class=\"layui-inline\">\r\n";
                            strValue += "                    <label class=\"layui-form-label\">" + strColumnComment2 + ":</label>\r\n";
                            strValue += "                    <div class=\"layui-input-inline\">\r\n";
                            strValue += "                    <select id=\"" + strColumnName + "\" name=\"" + strColumnName + "\">\r\n";
                            strValue += "                        <option value=\"\">选择" + strColumnComment2 + "</option>\r\n";
                            strValue += "                    </select>\r\n";
                            strValue += "                    </div>\r\n";
                            //strValue += "                    "+ GetSelectScript(strProjectName,strTableName);
                            strValue += "                </div>\r\n";

                            strReturnValue += strValue;
                        }
                        else if (strColumnComment.Contains("{勾选}"))
                        {
                            string strValue = "                <div class=\"layui-inline\">\r\n";
                            strValue += "                    <label class=\"layui-form-label\">" + strColumnComment2 + ":</label>\r\n";
                            strValue += "                    <div class=\"layui-input-inline\">\r\n";
                            strValue += "                    <select id=\"" + strColumnName + "\" name=\"" + strColumnName + "\">\r\n";
                            strValue += "                        <option value=\"\">请选择</option>\r\n";
                            strValue += "                        <option value=\"1\">是</option>\r\n";
                            strValue += "                        <option value=\"0\">否</option>\r\n";
                            strValue += "                    </select>\r\n";
                            strValue += "                    </div>\r\n";
                            //strValue += "                    "+ GetSelectScript(strProjectName,strTableName);
                            strValue += "                </div>\r\n";

                            strReturnValue += strValue;
                        }
                        else
                        {
                            string strValue = "                <div class=\"layui-inline\">\r\n";
                            strValue += "                    <label class=\"layui-form-label\">" + strColumnComment2 + ":</label>\r\n";
                            strValue += "                    <div class=\"layui-input-inline\">\r\n";
                            if (!string.IsNullOrEmpty(strMaxLength))
                            {
                                strValue += "                        <input type=\"" + strInputType + "\" id=\"" + strColumnName + "\" name=\"" + strColumnName + "\" maxlength=\"" + strMaxLength + "\" placeholder=\"请输入" + strColumnComment2 + "\" autocomplete=\"off\" class=\"layui-input\">\r\n";
                            }
                            else
                            {
                                strValue += "                        <input type=\"" + strInputType + "\" id=\"" + strColumnName + "\" name=\"" + strColumnName + "\" placeholder=\"请输入" + strColumnComment2 + "\" autocomplete=\"off\" class=\"layui-input\">\r\n";
                            }
                            strValue += "                    </div>\r\n";
                            strValue += "                </div>\r\n";

                            strReturnValue += strValue;
                        }

                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取搜索字段列表", "GetSearchItemList", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取新增字段列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetCreateItemList(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                int num = 0;
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME,CHARACTER_MAXIMUM_LENGTH FROM `information_schema`.`COLUMNS` WHERE TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strMaxLength = dr["CHARACTER_MAXIMUM_LENGTH"].ToString();//字段长度
                    string strDataType = dr["DATA_TYPE"].ToString();//数据类型

                    string strInputType = "text";
                    if (strDataType == "int" || strDataType == "bigint" || strDataType == "smalint" || strDataType == "decimal" || strDataType == "double")
                    {
                        strInputType = "number";
                    }

                    if (strColumnKey == "PRI" || strColumnName == "created_at" || strColumnName == "city_id" || strColumnName == "district_id" || strColumnName == "visit_num")
                    {
                        // 不生成UI
                    }
                    else
                    {
                        if (strColumnComment.Contains("{勾选}"))
                        {
                            string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);
                            string strColumnComment3 = CommonHelper.GetColumnKeyCommentRight(strColumnComment);

                            string strValue = "                        <div class=\"layui-form-item\">\r\n";
                            strValue += "                            <label class=\"layui-form-label\">" + strColumnComment2 + "</label>\r\n";
                            strValue += "                            <div class=\"layui-input-block\">\r\n";
                            strValue += "                                <input type=\"checkbox\" lay-verify=\"required\" lay-filter=\"switch_" + strColumnName + "\" id=\"switch_" + strColumnName + "\"  name=\"switch_" + strColumnName + "\" lay-skin=\"switch\" lay-text=\"" + strColumnComment3 + "\" checked>\r\n";
                            strValue += "                                <input type=\"hidden\" name=\"" + strColumnName + "\" id=\"" + strColumnName + "\" value=\"true\" />\r\n";
                            strValue += "                            </div>\r\n";
                            strValue += "                        </div>\r\n";
                            strReturnValue += strValue;
                        }
                        else if (strColumnComment.Contains("{下拉}"))
                        {
                            string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                            string strValue = "                        <div class=\"layui-form-item\">\r\n";
                            strValue += "                            <label class=\"layui-form-label\">" + strColumnComment2 + "</label>\r\n";
                            strValue += "                            <div class=\"layui-input-block\">\r\n";
                            strValue += "                                    <select id=\"" + strColumnName + "\" name=\"" + strColumnName + "\" lay-verify=\"required\">\r\n";
                            strValue += "                                        <option value=\"\">选择" + strColumnComment2 + "</option>\r\n";
                            strValue += "                                    </select>\r\n";
                            strValue += "                            </div>\r\n";
                            strValue += "                        </div>\r\n";
                            strReturnValue += strValue;
                        }
                        else if (strColumnComment.Contains("{图片}") || strColumnComment.Contains("头像") || strColumnName.Contains("avatar") || strColumnName.Contains("logo") || strColumnName.Contains("img") || strColumnName.Contains("path"))
                        {
                            string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                            string strValue = "                        <div class=\"layui-form-item\">\r\n";
                            strValue += "                            <label class=\"layui-form-label\">" + strColumnComment2 + "</label>\r\n";
                            strValue += "                            <div class=\"layui-input-block\">\r\n";
                            strValue += "                                    <div class=\"layui-upload-drag\" id=\"cover-upload-drag\">\r\n";
                            strValue += "                                        <i class=\"layui-icon\"></i>\r\n";
                            strValue += "                                        <p>点击上传，或将图片拖拽到此处</p>\r\n";
                            strValue += "                                        <label style=\"color:#dc2828\">*图片比例建议:16*9</label>\r\n";
                            strValue += "                                    </div>\r\n";
                            strValue += "                            </div>\r\n";
                            strValue += "                        </div>\r\n";
                            strReturnValue += strValue;
                        }
                        else if (strColumnComment.Contains("省"))
                        {
                            string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                            string strValue = "                        <div class=\"layui-form-item\">\r\n";
                            strValue += "                            <label class=\"layui-form-label\">区域</label>\r\n";
                            strValue += "                            <div class=\"layui-input-inline\" style=\"width: 120px;\">\r\n";
                            strValue += "                                <select id=\"province_id\" name=\"province_id\" lay-filter=\"select_province_id\" lay-verify=\"required\">\r\n";
                            strValue += "                                    <option value=\"\">选择省</option>\r\n";
                            strValue += "                                </select>\r\n";
                            strValue += "                            </div>\r\n";
                            strValue += "                            <div class=\"layui-input-inline\" style=\"width: 120px;\">\r\n";
                            strValue += "                                <select id=\"city_id\" name=\"city_id\" lay-filter=\"select_city_id\" lay-verify=\"required\">\r\n";
                            strValue += "                                    <option value=\"\">选择市</option>\r\n";
                            strValue += "                                </select>\r\n";
                            strValue += "                            </div>\r\n";
                            strValue += "                            <div class=\"layui-input-inline\" style=\"width: 120px;\">\r\n";
                            strValue += "                                <select id=\"district_id\" name=\"district_id\" lay-filter=\"select_district_id\" lay-verify=\"required\">\r\n";
                            strValue += "                                    <option value=\"\">选择区</option>\r\n";
                            strValue += "                                </select>\r\n";
                            strValue += "                            </div>\r\n";
                            strValue += "                        </div>\r\n";
                            strValue += "    \r\n";

                            strReturnValue += strValue;
                        }
                        else if (strColumnComment.Contains("发布人"))
                        {
                            strReturnValue += "";
                        }
                        else
                        {
                            string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                            string strValue = "                        <div class=\"layui-form-item\">\r\n";
                            if (num == 0)
                            {
                                strValue += "                            <label class=\"layui-form-label\"><span style=\"color:red\">*</span> " + strColumnComment2 + "</label>\r\n";
                            }
                            else
                            {
                                strValue += "                            <label class=\"layui-form-label\">" + strColumnComment2 + "</label>\r\n";
                            }
                            strValue += "                            <div class=\"layui-input-block\">\r\n";
                            if (strColumnName.Contains("remark") || strColumnName.Contains("summary") || strColumnName.Contains("content") || strColumnName.Contains("content") || strColumnName.Contains("content") || strColumnName.Contains("intro") || strDataType == "longtext")
                            {
                                if (strColumnComment.Contains("{富文本}") || strDataType.Contains("text") && strColumnName.Contains("intro"))
                                {
                                    strValue += "                                <textarea id=\"edit_content\" name=\"edit_content\" placeholder=\"请输入" + strColumnComment2 + "\" autocomplete=\"off\" class=\"layui-textarea\"></textarea>\r\n";
                                }
                                else
                                {
                                    strValue += "                                <textarea id=\"" + strColumnName + "\" name=\"" + strColumnName + "\" lay-verify=\"required\" placeholder=\"请输入" + strColumnComment2 + "\" autocomplete=\"off\" class=\"layui-textarea\"></textarea>\r\n";
                                }
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(strMaxLength))
                                {
                                    strValue += "                                <input type=\"text\" id=\"" + strColumnName + "\" name=\"" + strColumnName + "\" maxlength=\"" + strMaxLength + "\" lay-verify=\"required\" placeholder=\"请输入" + strColumnComment2 + "\" autocomplete=\"off\" class=\"layui-input\">\r\n";
                                }
                                else
                                {
                                    strValue += "                                <input type=\"" + strInputType + "\" id=\"" + strColumnName + "\" name=\"" + strColumnName + "\" lay-verify=\"required\" placeholder=\"请输入" + strColumnComment2 + "\" autocomplete=\"off\" class=\"layui-input\">\r\n";
                                }
                            }
                            strValue += "                            </div>\r\n";
                            strValue += "                        </div>\r\n";
                            strReturnValue += strValue;

                            num++;
                        }
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取新增字段列表", "GetCreateItemList", false);
            }

            return strReturnValue;
        }

        /// <summary>
        /// 获取编辑字段列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetEditItemList(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME,CHARACTER_MAXIMUM_LENGTH FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strMaxLength = dr["CHARACTER_MAXIMUM_LENGTH"].ToString();//字段长度
                    string strDataType = dr["DATA_TYPE"].ToString();//数据类型

                    string strInputType = "text";
                    if (strDataType == "int" || strDataType == "bigint" || strDataType == "smalint" || strDataType == "decimal" || strDataType == "double")
                    {
                        strInputType = "number";
                    }

                    if (strColumnKey == "PRI" || strColumnName == "created_at" || strColumnName == "city_id" || strColumnName == "district_id" || strColumnName == "visit_num")
                    {
                        // 不生成UI
                    }
                    else
                    {

                        if (strColumnComment.Contains("{勾选}"))
                        {
                            string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);
                            string strColumnComment3 = CommonHelper.GetColumnKeyCommentRight(strColumnComment);
                            strColumnComment3 = strColumnComment3.Replace("1=", "");
                            strColumnComment3 = strColumnComment3.Replace("0=", "");

                            string strValue = "                        <div class=\"layui-form-item\">\r\n";
                            strValue += "                            <label class=\"layui-form-label\">" + strColumnComment2 + "</label>\r\n";
                            strValue += "                            <div class=\"layui-input-block\">\r\n";
                            strValue += "                                <input type=\"checkbox\" lay-verify=\"required\" lay-filter=\"switch_" + strColumnName + "\" id=\"switch_" + strColumnName + "\" name=\"switch_" + strColumnName + "\" lay-skin=\"switch\" lay-text=\"" + strColumnComment3 + "\" checked=\"checked\">\r\n";
                            strValue += "                                <input type=\"hidden\" name=\"" + strColumnName + "\" id=\"" + strColumnName + "\" value=\"true\" />\r\n";
                            strValue += "                            </div>\r\n";
                            strValue += "                        </div>\r\n";

                            strReturnValue += strValue;
                        }
                        else if (strColumnComment.Contains("{下拉}"))
                        {
                            string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                            string strValue = "                        <div class=\"layui-form-item\">\r\n";
                            strValue += "                            <label class=\"layui-form-label\">" + strColumnComment2 + "</label>\r\n";
                            strValue += "                            <div class=\"layui-input-block\">\r\n";
                            strValue += "                            <select id=\"" + strColumnName + "\" name=\"" + strColumnName + "\" lay-verify=\"required\">\r\n";
                            strValue += "                                <option value=\"\">选择" + strColumnComment2 + "</option>\r\n";
                            strValue += "                            </select>\r\n";
                            strValue += "                            </div>\r\n";
                            strValue += "                        </div>\r\n";

                            strReturnValue += strValue;
                        }
                        else if (strColumnComment.Contains("{图片}") || strColumnComment.Contains("头像") || strColumnName.Contains("avatar") || strColumnName.Contains("logo") || strColumnName.Contains("img") || strColumnName.Contains("path"))
                        {
                            string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                            string strValue = "                        <div class=\"layui-form-item\">\r\n";
                            strValue += "                            <label class=\"layui-form-label\">" + strColumnComment2 + "</label>\r\n";
                            strValue += "                            <div class=\"layui-input-block\">\r\n";
                            strValue += "                                <div class=\"layui-upload-drag\" id=\"cover-upload-drag\">\r\n";
                            strValue += "                                <i class=\"layui-icon\"></i>\r\n";
                            strValue += "                                <p>点击上传，或将图片拖拽到此处</p>\r\n";
                            strValue += "                                <label style=\"color:#dc2828\">*图片比例建议:16*9</label>\r\n";
                            strValue += "                            </div>\r\n";
                            strValue += "                             </div>\r\n";
                            strValue += "                        </div>\r\n";

                            strReturnValue += strValue;
                        }
                        else if (strColumnComment.Contains("省"))
                        {
                            string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                            string strValue = "                        <div class=\"layui-form-item\">\r\n";
                            strValue += "                            <label class=\"layui-form-label\">区域</label>\r\n";
                            strValue += "                            <div class=\"layui-input-inline\" style=\"width: 120px;\">\r\n";
                            strValue += "                                <select id=\"province_id\" name=\"province_id\" lay-filter=\"select_province_id\" lay-verify=\"required\">\r\n";
                            strValue += "                                    <option value=\"\">选择省</option>\r\n";
                            strValue += "                                </select>\r\n";
                            strValue += "                            </div>\r\n";
                            strValue += "                            <div class=\"layui-input-inline\" style=\"width: 120px;\">\r\n";
                            strValue += "                                <select id=\"city_id\" name=\"city_id\" lay-filter=\"select_city_id\" lay-verify=\"required\">\r\n";
                            strValue += "                                    <option value=\"\">选择市</option>\r\n";
                            strValue += "                                </select>\r\n";
                            strValue += "                            </div>\r\n";
                            strValue += "                            <div class=\"layui-input-inline\" style=\"width: 120px;\">\r\n";
                            strValue += "                                <select id=\"district_id\" name=\"district_id\" lay-filter=\"select_district_id\" lay-verify=\"required\">\r\n";
                            strValue += "                                    <option value=\"\">选择区</option>\r\n";
                            strValue += "                                </select>\r\n";
                            strValue += "                            </div>\r\n";
                            strValue += "                        </div>\r\n";
                            strValue += "    \r\n";

                            strReturnValue += strValue;
                        }
                        else if (strColumnComment.Contains("发布人"))
                        {
                            strReturnValue += "";
                        }
                        else
                        {
                            string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                            string strValue = "                        <div class=\"layui-form-item\">\r\n";
                            strValue += "                            <label class=\"layui-form-label\">" + strColumnComment2 + "</label>\r\n";
                            strValue += "                            <div class=\"layui-input-block\">\r\n";
                            if (strColumnName.Contains("remark") || strColumnName.Contains("summary") || strColumnName.Contains("content") || strColumnName.Contains("content") || strColumnName.Contains("intro") || strDataType == "longtext")
                            {
                                if (strColumnComment.Contains("{富文本}") || strDataType.Contains("text") && strColumnName.Contains("intro"))
                                {
                                    strValue += "                                <textarea id=\"edit_content\" name=\"edit_content\" placeholder=\"请输入" + strColumnComment2 + "\" autocomplete=\"off\" class=\"layui-textarea\"></textarea>\r\n";
                                }
                                else
                                {
                                    strValue += "                                <textarea id=\"" + strColumnName + "\" name=\"" + strColumnName + "\" lay-verify=\"required\" placeholder=\"请输入" + strColumnComment2 + "\" autocomplete=\"off\" class=\"layui-textarea\"></textarea>\r\n";
                                }
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(strMaxLength))
                                {
                                    strValue += "                                <input type=\"text\" id=\"" + strColumnName + "\" name=\"" + strColumnName + "\" maxlength=\"" + strMaxLength + "\" lay-verify=\"required\" placeholder=\"请输入" + strColumnComment2 + "\" autocomplete=\"off\" class=\"layui-input\">\r\n";
                                }
                                else
                                {
                                    strValue += "                                <input type=\"" + strInputType + "\" id=\"" + strColumnName + "\" name=\"" + strColumnName + "\" lay-verify=\"required\" placeholder=\"请输入" + strColumnComment2 + "\" autocomplete=\"off\" class=\"layui-input\">\r\n";
                                }
                            }
                            strValue += "                            </div>\r\n";
                            strValue += "                        </div>\r\n";

                            strReturnValue += strValue;
                        }
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取新增字段列表", "GetCreateItemList", false);
            }

            return strReturnValue;
        }

        /// <summary>
        /// 获取编辑字段充填值列表
        /// </summary>
        /// <param name="strProjectName"></param>
        /// <param name="strDBName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetEditItemValueList(string strProjectName, string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

                    if (strColumnKey == "PRI" || strColumnName == "created_at")
                    {
                        //
                    }
                    else
                    {
                        string strValue = "                    $(\"#" + strColumnName + "\").val(res.data." + strColumnName + ");\r\n";
                        if (strColumnComment.Contains("{图片}") || strColumnComment.Contains("头像") || strColumnName.Contains("avatar") || strColumnName.Contains("logo") || strColumnName.Contains("img") || strColumnName.Contains("path"))
                        {
                            strValue += "                    if(res.data." + strColumnName + "){\r\n";
                            strValue += "                        $(\"#cover-upload-drag\").html(\"<img style='max-width:200px;max-height:150px' src='\" + res.data.show_" + strColumnName + " +\"'>\");\r\n";
                            strValue += "                    }\r\n";
                        }
                        if (strColumnComment.Contains("{勾选}"))
                        {
                            strValue += "                    $(\"#switch_" + strColumnName + "\").prop(\"checked\", res.data." + strColumnName + ");\r\n";
                        }
                        if (strColumnComment.Contains("省"))
                        {
                            strValue += "                   // 设置省\r\n";
                            strValue += "                   admin.req({\r\n";
                            strValue += "                       url: '/areas/list?parent_id=1'\r\n";
                            strValue += "                       , done: function (res_province) {\r\n";
                            // strValue += "                           // console.log(\"res_province=\"+ res_province.data);\r\n";
                            strValue += "                           $.each(res_province.data, function (i, item) {\r\n";
                            // strValue += "                               // console.log(\"area_id=\"+res_province.data[i].area_id+\",province_id=\"+res.data.province_id);\r\n";
                            strValue += "                               if (res_province.data[i].area_id == res.data.province_id) {\r\n";
                            strValue += "                                   $(\"#province_id\").append(\"<option value=\\\"\" + res_province.data[i].area_id + \"\\\" selected >\" + res_province.data[i].area_name + \"</option>\");\r\n";
                            strValue += "                               }\r\n";
                            strValue += "                               else {\r\n";
                            strValue += "                                   $(\"#province_id\").append(\"<option value=\\\"\" + res_province.data[i].area_id + \"\\\" >\" + res_province.data[i].area_name + \"</option>\");\r\n";
                            strValue += "                               }\r\n";
                            strValue += "                           });\r\n";
                            strValue += "                           layui.form.render('select');\r\n";
                            strValue += "                       }\r\n";
                            strValue += "                   });\r\n";
                            strValue += "                   // 设置市\r\n";
                            strValue += "                   admin.req({\r\n";
                            strValue += "                       url: '/areas/list?parent_id='+ res.data.province_id\r\n";
                            strValue += "                       , done: function (res_city) {\r\n";
                            // strValue += "                           // console.log(res_city.data);\r\n";
                            strValue += "                           $.each(res_city.data, function (i, item) {\r\n";
                            strValue += "                               if (res_city.data[i].area_id == res.data.city_id) {\r\n";
                            strValue += "                                   $(\"#city_id\").append(\"<option value=\\\"\" + res_city.data[i].area_id + \"\\\" selected >\" + res_city.data[i].area_name + \"</option>\");\r\n";
                            strValue += "                               }\r\n";
                            strValue += "                               else {\r\n";
                            strValue += "                                   $(\"#city_id\").append(\"<option value=\\\"\" + res_city.data[i].area_id + \"\\\" >\" + res_city.data[i].area_name + \"</option>\");\r\n";
                            strValue += "                               }\r\n";
                            strValue += "                           });\r\n";
                            strValue += "                           layui.form.render('select');\r\n";
                            strValue += "                       }\r\n";
                            strValue += "                   });\r\n";
                            strValue += "                   // 设置区\r\n";
                            strValue += "                   admin.req({\r\n";
                            strValue += "                       url: '/areas/list?parent_id='+ res.data.city_id\r\n";
                            strValue += "                       , done: function (res_distrcit) {\r\n";
                            // strValue += "                           // console.log(res_distrcit.data);\r\n";
                            strValue += "                           $.each(res_distrcit.data, function (i, item) {\r\n";
                            strValue += "                               if (res_distrcit.data[i].area_id == res.data.district_id) {\r\n";
                            strValue += "                                   $(\"#district_id\").append(\"<option value=\\\"\" + res_distrcit.data[i].area_id + \"\\\" selected >\" + res_distrcit.data[i].area_name + \"</option>\");\r\n";
                            strValue += "                               }\r\n";
                            strValue += "                               else {\r\n";
                            strValue += "                                   $(\"#district_id\").append(\"<option value=\\\"\" + res_distrcit.data[i].area_id + \"\\\" >\" + res_distrcit.data[i].area_name + \"</option>\");\r\n";
                            strValue += "                               }\r\n";
                            strValue += "                           });\r\n";
                            strValue += "                           layui.form.render('select');\r\n";
                            strValue += "                       }\r\n";
                            strValue += "                   });\r\n";

                        }
                        strReturnValue += strValue;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取新增字段列表", "GetCreateItemList", false);
            }

            return strReturnValue;
        }

        /// <summary>
        /// 获取详情字段列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetViewsItemList(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                int num = 1;
                string strItemList = "";
                string strItemList1 = "";
                string strItemList2 = "";
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "'  ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                    if (!strColumnType.Contains("text") && !strColumnType.Contains("longtext"))
                    {
                        string strItem = "                        <div class=\"layui-inline\">\r\n";
                        if (num == 1)
                        {
                            strItem += "                            <label class=\"layui-form-label\" style=\"width: 200px\">ID：</label>\r\n";
                        }
                        else
                        {
                            strItem += "                            <label class=\"layui-form-label\" style=\"width: 200px\">" + strColumnComment2 + "：</label>\r\n";
                        }
                        strItem += "                            <div class=\"layui-input-inline\">\r\n";
                        if (strColumnKey == "PRI")
                        {
                            strItem += "                                <span class=\"layui-badge layui-bg-blue\" id=\"" + strColumnName + "\" style=\"margin-top: 10px;\">0</span>\r\n";
                        }
                        else if (strColumnName.Contains("is_"))
                        {
                            strItem += "                                <span id=\"" + strColumnName + "\"></span>\r\n";
                        }
                        else
                        {
                            strItem += "                                <input disabled=\"disabled\" type=\"text\" id=\"" + strColumnName + "\" name=\"" + strColumnName + "\" autocomplete=\"off\" class=\"layui-input\">\r\n";
                        }
                        strItem += "                            </div>\r\n";
                        strItem += "                        </div>\r\n";

                        if (num % 3 == 1)
                        {
                            if (num == 1)
                            {
                                strItemList = strItem;
                            }

                            string strValue = "                    <div class=\"layui-form-item\">\r\n";
                            strValue += strItemList;
                            strValue += "                    </div>\r\n";
                            strItemList1 += strValue;

                            strItemList = "";
                            strItemList2 = "";

                            if (num != 1)
                            {
                                strItemList = strItem;
                            }
                        }
                        else
                        {
                            strItemList += strItem;

                            strItemList2 += strItem;
                        }

                        num++;
                        
                    }
                }
                dr.Dispose();
                cn.Close();

                string strItem2 = "                    <div class=\"layui-form-item\">\r\n";
                strItem2 += strItemList2;
                strItem2 += "                    </div>\r\n";

                strReturnValue = strItemList1 + strItem2;
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取新增字段列表", "GetCreateItemList", false);
            }

            

            return strReturnValue;
        }

        /// <summary>
        /// 获取详情字段列表(内容/图片)
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetViewsSpecialItemList(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "'  ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                    if (strColumnComment.Contains("图片") || strColumnName.Contains("intro") || strColumnName.Contains("remark") || strColumnName.Contains("content") || strColumnType.Contains("text") || strColumnType.Contains("longtext") || strColumnType.Contains("avatar"))
                    {
                        string strItem = "        <div class=\"layui-col-md12\">\r\n";
                        strItem += "            <div class=\"layui-card\">\r\n";
                        strItem += "                <div class=\"layui-card-header\">"+ strColumnComment2 + "：</div>\r\n";
                        strItem += "                <div class=\"layui-card-body\" style=\"line-height: 25px;word-wrap: break-word; text-align: center; margin: auto 0; padding: 50px 100px;\" id=\"" + strColumnName + "\"></div>\r\n";
                        strItem += "            </div>\r\n";
                        strItem += "        </div>\r\n";

                        strReturnValue += strItem;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取新增字段列表", "GetViewsSpecialItemList", false);
            }

            return strReturnValue;
        }

        /// <summary>
        /// 获取编辑字段充填值列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetViewsItemValueList(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    string strValue = "                    $(\"#" + strColumnName + "\").val(res.data." + strColumnName + ");\r\n";

                    if (strColumnName.Contains("is_"))
                    {
                        strValue = "                    $(\"#" + strColumnName + "\").html(res.data." + strColumnName + " ? \"<span class=\\\"layui-badge layui-bg-green\\\" style=\\\"margin-top: 10px;\\\">是</span>\" : \"<span class=\\\"layui-badge layui-bg-gray\\\" style=\\\"margin-top: 10px;\\\">否</span>\");\r\n";
                    }

                    if (strColumnKey == "PRI" || strColumnName.Contains("intro") || strColumnName.Contains("remark") || strColumnName.Contains("content") || strColumnType.Contains("text") || strColumnType.Contains("longtext"))
                    {
                        strValue = "                    $(\"#" + strColumnName + "\").html(res.data." + strColumnName + ");\r\n";
                    }

                    if (strColumnComment.Contains("{图片}") || strColumnComment.Contains("头像") || strColumnName.Contains("avatar") || strColumnName.Contains("logo") || strColumnName.Contains("img") || strColumnName.Contains("path"))
                    {
                        strValue = "                    $(\"#" + strColumnName + "\").html(\"<a onclick='preview(this);' style='cursor: pointer'><img src='\" + res.data.show_" + strColumnName + " + \"' width='200'></a>\");\r\n";
                    }

                    if (strColumnName.Contains("created_at"))
                    {
                        strValue = "                    $(\"#" + strColumnName + "\").val(res.data.format_time);\r\n";
                    }

                    strReturnValue += strValue;
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取新增字段列表", "GetCreateItemList", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取上传图片字段
        /// </summary>
        /// <param name="strDBName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetImgColumnName(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

                    if (strColumnComment.Contains("{图片}")|| strColumnName.Contains("头像") || strColumnName.Contains("avatar"))
                    {
                        strReturnValue = strColumnName;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取上传图片字段", "GetImgColumnName", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取开关在列表支持动态更新字段
        /// </summary>
        /// <param name="strDBName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSwitchColumnName(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

                    if (strColumnComment.Contains("{开关}"))
                    {
                        strReturnValue = strColumnName;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取上传图片字段", "GetImgColumnName", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取是否包含排序字段
        /// </summary>
        /// <param name="strDBName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSortColumnName(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

                    if (strColumnComment.Contains("排序"))
                    {
                        strReturnValue = strColumnName;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取上传图片字段", "GetImgColumnName", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取开关在列表支持动态更新字段
        /// </summary>
        /// <param name="strDBName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSwitchColumnNameText(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

                    if (strColumnComment.Contains("{开关}"))
                    {
                        strColumnComment = CommonHelper.GetColumnKeyComment(strColumnComment);
                        strColumnComment = strColumnComment.Replace("1=", "");
                        strColumnComment = strColumnComment.Replace("0=", "");
                        strReturnValue = strColumnComment;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取上传图片字段", "GetImgColumnName", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取开关在列表支持动态更新字段
        /// </summary>
        /// <param name="strDBName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSwitchColumnNameText2(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

                    if (strColumnComment.Contains("{开关}"))
                    {
                        strColumnComment = CommonHelper.GetColumnKeyCommentRight(strColumnComment);
                        strColumnComment = strColumnComment.Replace("1=", "");
                        strColumnComment = strColumnComment.Replace("0=", "");
                        strReturnValue = strColumnComment;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取上传图片字段", "GetImgColumnName", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取上传图片隐藏输入框
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetUploadImgHiddenInput(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

                    if (strColumnComment.Contains("{图片}") || strColumnComment.Contains("头像") || strColumnName.Contains("avatar") || strColumnName.Contains("logo") || strColumnName.Contains("img") || strColumnName.Contains("path"))
                    {
                        string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                        string strValue = "                                <input type=\"hidden\" id=\"" + strColumnName + "\" name=\"" + strColumnName + "\" value=\"\" />";
                        strReturnValue += strValue;
                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取搜索字段列表", "GetSearchItemList", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取上传图片脚本
        /// </summary>
        /// <param name="strProjectName"></param>
        /// <param name="strDBName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetUploadImgScript(string strProjectName, string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释


                    if (strColumnComment.Contains("{图片}") || strColumnComment.Contains("头像") || strColumnName.Contains("avatar") || strColumnName.Contains("logo") || strColumnName.Contains("img") || strColumnName.Contains("path"))
                    {
                        string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                        string strValue = "        // 上传图片至服务端\r\n";
                        strValue += "        upload.render({\r\n";
                        strValue += "            elem: '#cover-upload-drag'\r\n";
                        strValue += "            ,headers: {\r\n";
                        strValue += "                'RequestVerificationToken': csrfToken\r\n";
                        strValue += "            }\r\n";
                        strValue += "            , url: '/upload/uploadimg?catalogue=service&open_breviary=true'\r\n";
                        strValue += "            , done: function (res) {\r\n";
                        strValue += "                // console.log(`res=${JSON.stringify(res)}`);\r\n";
                        strValue += "                if (res.code > 0) {\r\n";
                        strValue += "                    return layer.msg('上传失败');\r\n";
                        strValue += "                }\r\n";
                        strValue += "                $(\"#cover-upload-drag\").html('<img style=\"max-width:200px;max-height:150px\" src=\"' + res.data.src +'\">');\r\n";
                        strValue += "                $(\"#" + strColumnName + "\").val(res.path);\r\n";
                        strValue += "            }\r\n";
                        strValue += "        });";

                        strReturnValue += strValue;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取搜索字段列表", "GetSearchItemList", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取监听省市区选择脚本
        /// </summary>
        /// <param name="strProjectName"></param>
        /// <param name="strDBName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetAreaScriptListen(string strProjectName, string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

                    if (strColumnComment.Contains("省"))
                    {
                        string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                        string strValue = "        // 监听省份选择\r\n";
                        strValue += "        form.on('select(select_province_id)', function (data) {\r\n";
                        strValue += "            $(\"#city_id\").html('<option value=\"\">选择市</option>');\r\n";
                        strValue += "            // 选择市\r\n";
                        strValue += "            admin.req({\r\n";
                        strValue += "                url: '/areas/list?parent_id=' + data.value\r\n";
                        strValue += "                , done: function (res) {\r\n";
                        strValue += "                    layer.close(loading);\r\n";
                        strValue += "                    $.each(res.data, function (i, item) {\r\n";
                        strValue += "                        $(\"#city_id\").append(\"<option value=\\\"\" + res.data[i].area_id + \"\\\" >\" + res.data[i].area_name + \"</option>\");\r\n";
                        strValue += "                    });\r\n";
                        strValue += "                    form.render();\r\n";
                        strValue += "                }\r\n";
                        strValue += "            });\r\n";
                        strValue += "        });\r\n\r\n";
                        strValue += "        // 监听市选择\r\n";
                        strValue += "        form.on('select(select_city_id)', function (data) {\r\n";
                        strValue += "            $(\"#district_id\").html('<option value=\"\">选择区</option>');\r\n";
                        strValue += "            // 选择区\r\n";
                        strValue += "            admin.req({\r\n";
                        strValue += "                url: '/areas/list?parent_id=' + data.value\r\n";
                        strValue += "                , done: function (res) {\r\n";
                        strValue += "                    layer.close(loading);\r\n";
                        strValue += "                    $.each(res.data, function (i, item) {\r\n";
                        strValue += "                        $(\"#district_id\").append(\"<option value=\\\"\" + res.data[i].area_id + \"\\\" >\" + res.data[i].area_name + \"</option>\");\r\n";
                        strValue += "                    });\r\n";
                        strValue += "                    form.render();\r\n";
                        strValue += "                }\r\n";
                        strValue += "            });\r\n";
                        strValue += "        });";

                        strReturnValue += strValue;
                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取搜索字段列表", "GetSearchItemList", false);
            }

            return strReturnValue;

        }

        ///// <summary>
        ///// 获取默认加载下拉框填充组件
        ///// </summary>
        ///// <param name="strProjectName"></param>
        ///// <param name="strTableName"></param>
        ///// <returns></returns>
        //public static string GetSelectScript(string strProjectName, string strDBName, string strTableName, string strTablePrefix)
        //{
        //    string strReturnValue = "";

        //    try
        //    {
        //        MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
        //        cn.Open();
        //        string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
        //        MySqlCommand cmd = new MySqlCommand(strSql, cn);
        //        MySqlDataReader dr = cmd.ExecuteReader();
        //        while (dr.Read())
        //        {
        //            string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
        //            string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
        //            string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

        //            //{下拉}[ypk_exhibition_types]会展类型
        //            if (strColumnComment.Contains("{下拉}") && !strColumnComment.Contains("areas"))
        //            {
        //                string strComment = "";
        //                if (strColumnComment.Contains("["))
        //                {
        //                    string[] splitComment = strColumnComment.Split(new char[] { '[' });
        //                    strComment = splitComment[1];
        //                }
        //                if (strComment.Contains("]"))
        //                {
        //                    string[] splitComment = strComment.Split(new char[] { ']' });
        //                    strComment = splitComment[0];
        //                }

        //                //表名
        //                string strSelectTableName = strComment;
        //                string strSelectId = CommonHelper.GetPrimaryKey(strSelectTableName);
        //                string strSelectName = CommonHelper.GetKeyNameForSelect(strSelectTableName);

        //                strComment = strComment.Replace(strProjectName.ToLower() + "_", "");
        //                string strRouterName = strComment.ToLower();//如：newstypes
        //                strRouterName = strRouterName.Replace(strTablePrefix.ToLower(), "");
        //                strRouterName = strRouterName.Replace("_", "");

        //                string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);
        //                string strResult = strColumnName.Replace("_", "");

        //                string strValue = "            \r\n";
        //                strValue += "            // " + strColumnComment2 + "\r\n";
        //                strValue += "            admin.req({\r\n";
        //                strValue += "                url: '/" + strRouterName + "/select'\r\n";
        //                strValue += "                , done: function (res) {\r\n";
        //                strValue += "                    layer.close(loading);\r\n";
        //                // strValue += "                    // console.log(`res=${res_" + strResult + ".data}`);\r\n";
        //                strValue += "                    $.each(res.data, function (i, item) {\r\n";
        //                strValue += "                        $(\"#" + strSelectId + "\").append(\"<option value=\" + item." + strSelectId + " + \">\" + item." + strSelectName + " + \"</option>\");\r\n";
        //                strValue += "                    });\r\n";
        //                strValue += "                    layui.form.render('select');\r\n";
        //                strValue += "                }\r\n";
        //                strValue += "            });\r\n";
        //                strReturnValue += strValue;
        //            }
        //        }
        //        dr.Dispose();
        //        cn.Close();
        //    }
        //    catch (Exception ex)
        //    {
        //        CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取搜索字段列表", "GetSearchItemList", false);
        //    }

        //    return strReturnValue;

        //}

        /// <summary>
        /// 获取默认加载下拉框填充组件
        /// </summary>
        /// <param name="strProjectName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSelectArea(string strProjectName, string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

                    //
                    if (strColumnComment.Contains("省"))
                    {
                        string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                        string strValue = "            // " + strColumnComment2 + "\r\n";
                        strValue += "            admin.req({\r\n";
                        strValue += "                url: '/areas/list?parent_id=1'\r\n";
                        strValue += "                , done: function (res) {\r\n";
                        strValue += "                    layer.close(loading);\r\n";
                        strValue += "                    // console.log(`res=${res}`);\r\n";
                        strValue += "                    $.each(res.data, function (i, item) {\r\n";
                        strValue += "                        $(\"#province_id\").append(\"<option value=\\\"\" + res.data[i].area_id + \"\\\">\" + res.data[i].area_name + \"</option>\");\r\n";
                        strValue += "                    });\r\n";
                        strValue += "                    layui.form.render('select');\r\n";
                        strValue += "                }\r\n";
                        strValue += "            });\r\n";
                        strReturnValue += strValue;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取搜索字段列表", "GetSearchItemList", false);
            }

            return strReturnValue;

        }


        /// <summary>
        /// 获取监听开关脚本
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSwitchScript(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释


                    if (strColumnComment.Contains("{勾选}"))
                    {
                        string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                        string strValue = "        // 监听指定开关\r\n";
                        strValue += "        form.on('switch(switch_" + strColumnName + ")', function (data) {\r\n";
                        strValue += "            if (this.checked) {\r\n";
                        strValue += "                $(\"#" + strColumnName + "\").val(true);\r\n";
                        strValue += "            } else {\r\n";
                        strValue += "                $(\"#" + strColumnName + "\").val(false);\r\n";
                        strValue += "            }\r\n";
                        strValue += "        });";

                        strReturnValue += strValue;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取搜索字段列表", "GetSearchItemList", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取富文本编辑器字段
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetEditorKey(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strColumnType = dr["COLUMN_TYPE"].ToString();//注释

                    if (strColumnType == "longtext" || strColumnComment.Contains("富文本"))
                    {
                        strReturnValue = strColumnName;
                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取搜索字段列表", "GetSearchItemList", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取富文本编辑器
        /// </summary>
        /// <param name="strDBName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetRichEditColumnName(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strDataType = dr["DATA_TYPE"].ToString();//数据类型

                    if (strColumnComment.Contains("{富文本}") || strDataType.Contains("text") && strColumnName.Contains("intro"))
                    {
                        strReturnValue = strColumnName;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取上传图片字段", "GetImgColumnName", false);
            }

            return strReturnValue;

        }


        /// <summary>
        /// 获取搜索字段用于导出页面
        /// </summary>
        /// <param name="strDBName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSearchColumnForExport(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释
                    string strDataType = dr["DATA_TYPE"].ToString();//注释

                    if (strColumnComment.Contains("{搜索}"))
                    {
                        string strValue = "\"" + strColumnName + "\": $(\"#" + strColumnName + "\").val(), ";
                        strReturnValue += strValue;
                    }

                    if (strColumnName == "created_at")
                    {
                        strReturnValue += "\"select_date\": $(\"#" + strColumnName + "\").val(), ";
                    }
                }
                dr.Dispose();
                cn.Close();

                if (strReturnValue.Length > 0)
                {
                    strReturnValue = strReturnValue.Substring(0, strReturnValue.Length - 2);
                }
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取搜索字段", "GetSearchColumn", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取默认加载下拉框填充组件-新增页面
        /// </summary>
        /// <param name="strProjectName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSelectScript(string strProjectName, string strDBName, string strTableName, string strTablePrefix)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

                    //{下拉}[ypk_exhibition_types]会展类型
                    if (strColumnComment.Contains("{搜索}") || strColumnComment.Contains("{下拉}"))
                    {
                        if (strColumnComment.Contains("{下拉}") && !strColumnComment.Contains("areas"))
                        {
                            string strComment = "";
                            if (strColumnComment.Contains("["))
                            {
                                string[] splitComment = strColumnComment.Split(new char[] { '[' });
                                strComment = splitComment[1];
                            }
                            if (strComment.Contains("]"))
                            {
                                string[] splitComment = strComment.Split(new char[] { ']' });
                                strComment = splitComment[0];
                            }

                            //表名
                            string strSelectTableName = strComment;
                            string strSelectId = CommonHelper.GetPrimaryKey(strSelectTableName);
                            string strSelectName = CommonHelper.GetKeyNameForSelect(strSelectTableName);

                            strComment = strComment.Replace(strProjectName.ToLower() + "_", "");
                            string strRouterName = strComment.ToLower();//如：newstypes
                            strRouterName = strRouterName.Replace(strTablePrefix, "");
                            strRouterName = strRouterName.Replace(strTablePrefix.ToLower(), "");
                            strRouterName = strRouterName.Replace("_", "");

                            string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);
                            string strResult = strColumnName.Replace("_", "");

                            string strValue = "            \r\n";
                            strValue += "            // " + strColumnComment2 + "\r\n";
                            strValue += "            admin.req({\r\n";
                            strValue += "                url: '/" + strRouterName + "/select'\r\n";
                            strValue += "                , done: function (res) {\r\n";
                            strValue += "                    layer.close(loading);\r\n";
                            // strValue += "                    // console.log(res_" + strResult + ".data);\r\n";
                            strValue += "                    $.each(res.data, function (i, item) {\r\n";
                            strValue += "                        $(\"#" + strSelectId + "\").append(\"<option value=\" + item." + strSelectId + " + \">\" + item." + strSelectName + " + \"</option>\");\r\n";
                            strValue += "                    });\r\n";
                            strValue += "                    layui.form.render('select');\r\n";
                            strValue += "                }\r\n";
                            strValue += "            });\r\n";
                            strReturnValue += strValue;
                        }
                    }

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取搜索字段列表", "GetSearchItemList", false);
            }

            return strReturnValue;

        }

        /// <summary>
        /// 获取默认加载下拉框填充组件-编辑页面
        /// </summary>
        /// <param name="strProjectName"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetSelectScriptForEdit(string strProjectName, string strDBName, string strTableName, string strTablePrefix)
        {
            string strReturnValue = "";

            try
            {
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

                    //{下拉}[ypk_exhibition_types]会展类型
                    if (strColumnComment.Contains("{下拉}") && !strColumnComment.Contains("areas"))
                    {
                        string strComment = "";
                        if (strColumnComment.Contains("["))
                        {
                            string[] splitComment = strColumnComment.Split(new char[] { '[' });
                            strComment = splitComment[1];
                        }
                        if (strComment.Contains("]"))
                        {
                            string[] splitComment = strComment.Split(new char[] { ']' });
                            strComment = splitComment[0];
                        }

                        //表名
                        string strSelectTableName = strComment;
                        string strSelectId = CommonHelper.GetPrimaryKey(strSelectTableName);
                        string strSelectName = CommonHelper.GetKeyNameForSelect(strSelectTableName);

                        strComment = strComment.Replace(strProjectName.ToLower() + "_", "");
                        string strRouterName = strComment.ToLower();//如：newstypes
                        strRouterName = strRouterName.Replace(strTablePrefix.ToLower(), "");
                        strRouterName = strRouterName.Replace("_", "");

                        string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);
                        string strResult = strColumnName.Replace("_", "");

                        string strValue = "                    \r\n";
                        strValue += "                    // " + strColumnComment2 + "\r\n";
                        strValue += "                    admin.req({\r\n";
                        strValue += "                        url: '/" + strRouterName + "/select'\r\n";
                        strValue += "                        , done: function (res2) {\r\n";
                        // strValue += "                            // console.log(res_" + strResult + ".data);\r\n";
                        strValue += "                            $.each(res2.data, function (i, item) {\r\n";
                        strValue += "                                if (item." + strSelectId + " == res.data." + strSelectId + ") {\r\n";
                        strValue += "                                    $(\"#" + strSelectId + "\").append(\"<option value=\" + item." + strSelectId + " + \" selected>\" + item." + strSelectName + " + \"</option>\");\r\n";
                        strValue += "                                }\r\n";
                        strValue += "                                else {\r\n";
                        strValue += "                                    $(\"#" + strSelectId + "\").append(\"<option value=\" + item." + strSelectId + " + \">\" + item." + strSelectName + " + \"</option>\");\r\n";
                        strValue += "                                }\r\n";
                        strValue += "                            });\r\n";
                        strValue += "                            layui.form.render('select');\r\n";
                        strValue += "                        }\r\n";
                        strValue += "                    });\r\n";
                        strReturnValue += strValue;
                    }
                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取搜索字段列表", "GetSearchItemList", false);
            }

            return strReturnValue;

        }


        /// <summary>
        /// 获取表格显示字段列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static string GetTableColsList(string strDBName, string strTableName)
        {
            string strReturnValue = "";

            try
            {
                int num = 0;
                MySqlConnection cn = new MySqlConnection(CodeRobot.DBSqlHelper.DBMySQLHelper.ConnectionMySQL());
                cn.Open();
                string strSql = "SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,COLUMN_KEY,COLUMN_COMMENT,EXTRA,COLUMN_DEFAULT,CHARACTER_SET_NAME FROM `information_schema`.`COLUMNS` WHERE  TABLE_SCHEMA='" + strDBName + "' AND TABLE_NAME='" + strTableName + "' ORDER BY ordinal_position ";
                MySqlCommand cmd = new MySqlCommand(strSql, cn);
                MySqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string strColumnName = dr["COLUMN_NAME"].ToString();//字段列名
                    string strColumnKey = dr["COLUMN_KEY"].ToString();//是否是主键
                    string strColumnComment = dr["COLUMN_COMMENT"].ToString();//注释

                    string strColumnComment2 = CommonHelper.GetColumnKeyComment(strColumnComment);

                    string strValue = "                {\r\n";
                    strValue += "                    field: \"" + strColumnName + "\",\r\n";
                    strValue += "                    title: \"" + strColumnComment2 + "\",\r\n";
                    strValue += "                    width: 150\r\n";

                    if (strColumnName == "created_at")
                    {
                        //主键和日期需要排序
                        strValue = "                {\r\n";
                        strValue += "                    field: \"format_time\",\r\n";
                        strValue += "                    title: \"创建日期\",\r\n";
                        strValue += "                    sort: !0,\r\n";
                        strValue += "                    width: 180\r\n";
                    }
                    if (strColumnKey == "PRI")
                    {
                        // 主键设置宽度
                        strValue = "                {\r\n";
                        strValue += "                    type: \"numbers\",\r\n";
                        strValue += "                    title: \"序号\",\r\n";
                        strValue += "                    width: 80\r\n";
                    }
                    if (strColumnComment.Contains("{开关}"))
                    {
                        // 开关标记支持动态更新
                        strValue = "                {\r\n";
                        strValue += "                    field: \"" + strColumnName + "\",\r\n";
                        strValue += "                    title: \"" + strColumnComment2 + "\",\r\n";
                        strValue += "                    align: \"center\",\r\n";
                        strValue += "                    templet: \"#switchTpl\",\r\n";
                        strValue += "                    width: 120\r\n";
                    }
                    if (strColumnComment.Contains("{图片}")|| strColumnComment.Contains("头像")|| strColumnName.Contains("avatar"))
                    {
                        strValue = "                {\r\n";
                        strValue += "                    field: \"" + strColumnName + "\",\r\n";
                        strValue += "                    title: \"" + strColumnComment2 + "\",\r\n";
                        strValue += "                    templet: \"#imgTpl\",\r\n";
                        strValue += "                    width: 85\r\n";
                    }
                    if (strColumnComment.Contains("排序"))
                    {
                        // 排序字段支持可编辑
                        strValue = "                {\r\n";
                        strValue += "                    field: \"" + strColumnName + "\",\r\n";
                        strValue += "                    title: \"" + strColumnComment2 + "\",\r\n";
                        strValue += "                    edit: \"text\",\r\n";
                        strValue += "                    align: \"center\",\r\n";
                        strValue += "                    style: \"background-color: #e8f1ff; color: #666;\",\r\n";
                        strValue += "                    width: 100\r\n";
                    }
                    if (strColumnName.Contains("user_id"))
                    {
                        // 处理用户名
                        strValue = "                {\r\n";
                        strValue += "                    field: \"user_name\",\r\n";
                        strValue += "                    title: \"" + strColumnComment2 + "\",\r\n";
                        strValue += "                    width: 150\r\n";
                    }

                    // 第一列加超链接
                    if (num == 1)
                    {
                        strValue = "                {\r\n";
                        strValue += "                    field: \"" + strColumnName + "\",\r\n";
                        strValue += "                    title: \"" + strColumnComment2 + "\",\r\n";
                        strValue += "                    templet: \"#linkTpl\",\r\n";
                        strValue += "                    width: 200\r\n";
                    }

                    strValue += "                },\r\n";

                    strReturnValue += strValue;
                    num++;

                }
                dr.Dispose();
                cn.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(CodeHelper), ex, "获取搜索字段列表", "GetSearchItemList", false);
            }

            return strReturnValue;

        }

    }
}
